﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.TestManagement.Client;

namespace TFSTools.TFSLibrary.TestManagement
{
    public sealed class TFSTestManagement : TFSServerEntity
    {
        private ITestManagementService serverTestManagementService;
        private TFSTestTeamProject tfsTestTeamProject = null;

        internal TFSTestManagement(ITFSConnection connection)
            : base(connection)
        {
            this.serverTestManagementService = this.SelectedTeamProjectCollection.GetService<ITestManagementService>();
        }

        internal ITestManagementService Service { get { return this.serverTestManagementService; } }

        public TFSTestTeamProject TestTeamProject
        {
            get
            {
                if (this.tfsTestTeamProject == null)
                {
                    var teamProject = this.serverTestManagementService.GetTeamProject(Connection.SelectedProject.Name);
                    this.tfsTestTeamProject = new TFSTestTeamProject(Connection, teamProject);
                }

                return this.tfsTestTeamProject;
            }
        }

        public override string ToString() { return this.serverTestManagementService.ToString(); }
    }
}
